#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
void error(const char *msg)
{
	perror(msg);
	exit(1);
}

int main()
{
	int sockfd = socket(AF_INET, SOCK_STREAM, 0);
	sockaddr_in serv_addr;
	memset(&serv_addr, 0, sizeof(serv_addr));
	serv_addr.sin_family = AF_INET;
	inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr);
	serv_addr.sin_port = 46572;
	if (connect(sockfd, (sockaddr*)&serv_addr, sizeof(serv_addr)) < 0)
		error("error connecting");
	printf("Message: ");
	char buf[1<<10];
	memset(buf, 0, sizeof(buf));
	scanf("%[^\n]", buf);


	write(sockfd, buf, strlen(buf)+1);
	memset(buf, 0, sizeof(buf));
	read(sockfd, buf, 1<<10);
	printf("Response: %s\n", buf);

	return 0;
}
